package com.sims.service.impl;

import java.util.List;

import com.sims.dao.IStnUserDao;
import com.sims.dao.impl.StnUserDaoImp;
import com.sims.eo.StnUser;
import com.sims.service.IUserService;

public class UserServiceImp implements IUserService {

	IStnUserDao stnUserDao = new StnUserDaoImp();


	public boolean validateLogin(String userAccount, String userPassword) {
		StnUser stnUser = stnUserDao.getUserbyAccount(userAccount);
		boolean validate = false;
		if (stnUser != null) {
			if (stnUser.getUserPassword().equals(userPassword)) {
				validate = true;
			}
		}
		return validate;
	}


	public List<StnUser> getAllStnUser() {
		return stnUserDao.getAllStnUser();
	}


	public boolean deletStnUserById(Long id) {
		return stnUserDao.deletStnUserById(id);
	}


	public StnUser getStnUserById(Long id) {
		return stnUserDao.getStnUserById(id);
	}


	public Long createStnUser(StnUser user) {
		return stnUserDao.createStnUser(user);
	}


	public boolean updateStnUser(StnUser user) {
		StnUser userdb = getStnUserById(user.getId());
		if (user.getUserAccount() != null) {
			userdb.setUserAccount(user.getUserAccount());
		}
		if (user.getUserName() != null) {
			userdb.setUserName(user.getUserName());
		}
		if (user.getUserPassword() != null) {
			userdb.setUserPassword(user.getUserPassword());
		}
		if (user.getCellphone() != null) {
			userdb.setCellphone(user.getCellphone());
		}
		return stnUserDao.updateStnUser(userdb);
	}


	public List<StnUser> getAllStnUser(int pageNo, int pageSize) {
		return stnUserDao.getAllStnUser(pageNo, pageSize);
	}


	public long getRowCount() {
		return stnUserDao.getRowCount();
	}

}
